package c.c.b.a.b;

import c.c.b.a.b.a.c.g;
import c.c.b.a.b.a.e;
import c.c.b.a.b.a.k.c;
import com.huawei.hms.android.HwBuildEx.VersionCodes;
import java.lang.ref.Reference;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.Socket;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.net.SocketFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;

/* compiled from: OkHttpClient */
public class z implements Cloneable {
    public static final List<a0> A = e.l(a0.HTTP_2, a0.HTTP_1_1);
    public static final List<n> B = e.l(n.f, n.g);
    public final q a;
    public final Proxy b;
    public final List<a0> c;
    public final List<n> d;
    public final List<x> e;
    public final List<x> f;
    public final c.c.b.a.b.s.b g;
    public final ProxySelector h;
    public final p i;
    public final c.c.b.a.b.a.a.e j;
    public final SocketFactory k;
    public final SSLSocketFactory l;
    public final c m;
    public final HostnameVerifier n;
    public final k o;
    public final h p;
    public final h q;
    public final m r;
    public final r s;
    public final boolean t;
    public final boolean u;
    public final boolean v;
    public final int w;
    public final int x;
    public final int y;
    public final int z;

    /* compiled from: OkHttpClient */
    public static final class b {
        public q a;
        public Proxy b;
        public List<a0> c;
        public List<n> d;
        public final List<x> e;
        public final List<x> f;
        public c.c.b.a.b.s.b g;
        public ProxySelector h;
        public p i;
        public c.c.b.a.b.a.a.e j;
        public SocketFactory k;
        public SSLSocketFactory l;
        public c m;
        public HostnameVerifier n;
        public k o;
        public h p;
        public h q;
        public m r;
        public r s;
        public boolean t;
        public boolean u;
        public boolean v;
        public int w;
        public int x;
        public int y;
        public int z;

        public b() {
            this.e = new ArrayList();
            this.f = new ArrayList();
            this.a = new q();
            this.c = z.A;
            this.d = z.B;
            this.g = new t(s.a);
            this.h = ProxySelector.getDefault();
            this.i = p.a;
            this.k = SocketFactory.getDefault();
            this.n = c.c.b.a.b.a.k.e.a;
            this.o = k.c;
            h hVar = h.a;
            this.p = hVar;
            this.q = hVar;
            this.r = new m();
            this.s = r.a;
            this.t = true;
            this.u = true;
            this.v = true;
            this.w = VersionCodes.CUR_DEVELOPMENT;
            this.x = VersionCodes.CUR_DEVELOPMENT;
            this.y = VersionCodes.CUR_DEVELOPMENT;
            this.z = 0;
        }

        public b a(long j, TimeUnit timeUnit) {
            this.w = e.e("timeout", j, timeUnit);
            return this;
        }

        public b b(SSLSocketFactory sSLSocketFactory) {
            Objects.requireNonNull(sSLSocketFactory, "sslSocketFactory == null");
            this.l = sSLSocketFactory;
            c.c.b.a.b.a.i.e eVar = c.c.b.a.b.a.i.e.a;
            X509TrustManager f = eVar.f(sSLSocketFactory);
            if (f != null) {
                this.m = eVar.a(f);
                return this;
            }
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Unable to extract the trust manager on ");
            stringBuilder.append(eVar);
            stringBuilder.append(", sslSocketFactory is ");
            stringBuilder.append(sSLSocketFactory.getClass());
            throw new IllegalStateException(stringBuilder.toString());
        }

        public b c(long j, TimeUnit timeUnit) {
            this.x = e.e("timeout", j, timeUnit);
            return this;
        }

        public b d(long j, TimeUnit timeUnit) {
            this.y = e.e("timeout", j, timeUnit);
            return this;
        }

        public b(z zVar) {
            ArrayList arrayList = new ArrayList();
            this.e = arrayList;
            ArrayList arrayList2 = new ArrayList();
            this.f = arrayList2;
            this.a = zVar.a;
            this.b = zVar.b;
            this.c = zVar.c;
            this.d = zVar.d;
            arrayList.addAll(zVar.e);
            arrayList2.addAll(zVar.f);
            this.g = zVar.g;
            this.h = zVar.h;
            this.i = zVar.i;
            this.j = zVar.j;
            this.k = zVar.k;
            this.l = zVar.l;
            this.m = zVar.m;
            this.n = zVar.n;
            this.o = zVar.o;
            this.p = zVar.p;
            this.q = zVar.q;
            this.r = zVar.r;
            this.s = zVar.s;
            this.t = zVar.t;
            this.u = zVar.u;
            this.v = zVar.v;
            this.w = zVar.w;
            this.x = zVar.x;
            this.y = zVar.y;
            this.z = zVar.z;
        }
    }

    /* compiled from: OkHttpClient */
    public static class a extends c.c.b.a.b.a.b {
        public c.c.b.a.b.a.c.c a(m mVar, b bVar, g gVar, f fVar) {
            for (c.c.b.a.b.a.c.c cVar : mVar.d) {
                if (cVar.h(bVar, fVar)) {
                    gVar.d(cVar, true);
                    return cVar;
                }
            }
            return null;
        }

        public Socket b(m mVar, b bVar, g gVar) {
            for (c.c.b.a.b.a.c.c cVar : mVar.d) {
                if (cVar.h(bVar, null) && cVar.j() && cVar != gVar.g()) {
                    if (gVar.m == null && gVar.j.n.size() == 1) {
                        Reference reference = (Reference) gVar.j.n.get(0);
                        Socket c = gVar.c(true, false, false);
                        gVar.j = cVar;
                        cVar.n.add(reference);
                        return c;
                    }
                    throw new IllegalStateException();
                }
            }
            return null;
        }

        public void c(c.c.b.a.b.v.a aVar, String str, String str2) {
            aVar.a.add(str);
            aVar.a.add(str2.trim());
        }
    }

    static {
        c.c.b.a.b.a.b.a = new a();
    }

    public z() {
        this(new b());
    }

    public j a(c0 c0Var) {
        b0 b0Var = new b0(this, c0Var, false);
        b0Var.c = ((t) this.g).a;
        return b0Var;
    }

    public z(b bVar) {
        String str = "No System TLS";
        this.a = bVar.a;
        this.b = bVar.b;
        this.c = bVar.c;
        List<n> list = bVar.d;
        this.d = list;
        this.e = e.k(bVar.e);
        this.f = e.k(bVar.f);
        this.g = bVar.g;
        this.h = bVar.h;
        this.i = bVar.i;
        this.j = bVar.j;
        this.k = bVar.k;
        loop0:
        while (true) {
            Object obj = null;
            for (n nVar : list) {
                if (obj != null || nVar.a) {
                    obj = 1;
                }
            }
            break loop0;
        }
        SSLSocketFactory sSLSocketFactory = bVar.l;
        if (sSLSocketFactory != null || obj == null) {
            this.l = sSLSocketFactory;
            this.m = bVar.m;
        } else {
            try {
                TrustManagerFactory instance = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                instance.init(null);
                TrustManager[] trustManagers = instance.getTrustManagers();
                if (trustManagers.length == 1 && (trustManagers[0] instanceof X509TrustManager)) {
                    X509TrustManager x509TrustManager = (X509TrustManager) trustManagers[0];
                    try {
                        SSLContext instance2 = SSLContext.getInstance("TLS");
                        instance2.init(null, new TrustManager[]{x509TrustManager}, null);
                        str = instance2.getSocketFactory();
                        this.l = str;
                        this.m = c.c.b.a.b.a.i.e.a.a(x509TrustManager);
                    } catch (GeneralSecurityException e) {
                        throw e.f(str, e);
                    }
                }
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Unexpected default trust managers:");
                stringBuilder.append(Arrays.toString(trustManagers));
                throw new IllegalStateException(stringBuilder.toString());
            } catch (GeneralSecurityException e2) {
                throw e.f(str, e2);
            }
        }
        this.n = bVar.n;
        k kVar = bVar.o;
        c cVar = this.m;
        if (!e.r(kVar.b, cVar)) {
            kVar = new k(kVar.a, cVar);
        }
        this.o = kVar;
        this.p = bVar.p;
        this.q = bVar.q;
        this.r = bVar.r;
        this.s = bVar.s;
        this.t = bVar.t;
        this.u = bVar.u;
        this.v = bVar.v;
        this.w = bVar.w;
        this.x = bVar.x;
        this.y = bVar.y;
        this.z = bVar.z;
        StringBuilder g;
        if (this.e.contains(null)) {
            g = c.b.a.a.a.g("Null interceptor: ");
            g.append(this.e);
            throw new IllegalStateException(g.toString());
        } else if (this.f.contains(null)) {
            g = c.b.a.a.a.g("Null network interceptor: ");
            g.append(this.f);
            throw new IllegalStateException(g.toString());
        }
    }
}
